package com.wsseieiei.fireballgame.events;

import com.wsseieiei.fireballgame.Main;
import com.wsseieiei.fireballgame.init.ItemInit;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraftforge.event.entity.living.LivingHurtEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

@Mod.EventBusSubscriber(modid= Main.MOD_ID)
public class ModNoFallEvent {
    @SubscribeEvent
    public static void noFall(LivingHurtEvent event){
        Level world = event.getEntityLiving().level;
        LivingEntity hurtOne = event.getEntityLiving();
        Entity attacker = event.getSource().getEntity();
        if ((attacker == null) && (hurtOne instanceof Player) && (event.getSource().isFall())){
            if (hurtOne.getItemBySlot(EquipmentSlot.MAINHAND).getItem() == ItemInit.SLIME_PLATE.get()) {
                hurtOne.addEffect(new MobEffectInstance(MobEffects.LEVITATION, 5, 10, true, true));
                event.setCanceled(true);
            }
            }
        }
    }
